﻿using Kenly.DBFramework.TestModel.Purchasing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Kenly.DBFramework.Gateway;
using System.Collections.Generic;

using System.Linq;
using System.Web;
using System.Web.UI;

namespace Kenly.DBFramework.Tests
{


    /// <summary>
    ///这是 VendorTest 的测试类，旨在
    ///包含所有 VendorTest 单元测试
    ///</summary>
    [TestClass()]
    public class SerializableTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试属性
        // 
        //编写测试时，还可使用以下属性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///
        ///</summary>
        [TestMethod()]
        public void SerializeTableEntityTest()
        {
            string msg = "SerializeTableEntity did not return the expected value.";

            List<Vendor> vendors = Vendor.CreateInstances(2);

            vendors[0].AccountNumber = "1234567890";

            StateBag state = new StateBag();
            state["vendors"] = vendors;

            List<Vendor> vendorsFromStateBag = state["vendors"] as List<Vendor>;

            Assert.IsTrue(
                vendorsFromStateBag[0].AccountNumber == vendors[0].AccountNumber, msg);

            Assert.IsTrue(vendorsFromStateBag.Equals(vendors), msg);

            int vendorsHashCode=vendors.GetHashCode();
            int vendorsFromStateBagHashCode=vendorsFromStateBag.GetHashCode();

            Assert.IsTrue(vendorsFromStateBagHashCode == vendorsHashCode,
                msg + "vendorsHashCode=" + vendorsHashCode + 
                ",vendorsFromStateBagHashCode=" + vendorsFromStateBagHashCode);

        }

        [TestMethod()]
        public void SerializeOrderTest()
        {
            string msg = "SerializeOrder did not return the expected value.";

            Vendor target = new Vendor();

            target.AccountNumber = "1234567890";

            StateBag state = new StateBag();
            state["vendor"] = target;

            Vendor vendorFromStateBag = state["vendor"] as Vendor;

            Assert.IsTrue(
                vendorFromStateBag.AccountNumber == target.AccountNumber, msg);

            Assert.IsTrue(vendorFromStateBag.Equals(target), msg);
        }
    }
}
